/// 通用响应对象类
class BaseResponse<T> {
  /// 响应状态码，调用成功返回00000
  String? code;

  /// 错误提示信息
  String? message;

  /// 服务器当前时间戳
  int? timestamp;

  /// 响应主体内容
  T? content;

  /// 异常信息
  String? error;

  /// 错误代码
  String? errorCode;

  BaseResponse({
    this.code,
    this.message,
    this.timestamp,
    this.content,
    this.error,
    this.errorCode,
  });

  /// 从Map<String, dynamic>创建BaseResponse
  factory BaseResponse.fromJson(
    Map<String, dynamic> json, {
    T Function(dynamic)? fromJsonT,
  }) {
    return BaseResponse(
      code: json['code'],
      message: json['message'],
      timestamp: json['timestamp'],
      content: json['content'] != null
          ? fromJsonT?.call(json['content']) ?? json['content']
          : null,
      error: json['error'],
      errorCode: json['errorCode'],
    );
  }
}
